<?php
/**
 * Created by PhpStorm.
 * User: chen
 * Date: 2016/4/22
 * Time: 14:18
 */

$this->title = '有试吗-有事没事来试试';

?>
<?php $this->beginBlock('css');?>
<link rel="stylesheet" type="text/css" href="<?=Yii::getAlias('@static')?>/wap/minisite/zjd/css/zjd.css">
<?php $this->endBlock();?>

<section>
    <header>
        <div class="title">
            <div class="header-left" onclick="$.go('<?=Yii::$app->urlManager->createUrl(Yii::$app->controller->id . '/index')?>');">
                <span class="icon icon-arrow-left"></span>
            </div>
            <h1>砸金蛋</h1>
        </div>
    </header>
    <article>
        <div class="zjd_bg"></div>
        <div class="zjd_title"></div>
        <div class="zjd_jd zjd_jd1"><div data-hammer="hammer1"></div></div>
        <div class="zjd_jd zjd_jd2"><div data-hammer="hammer2"></div></div>
        <div class="zjd_jd zjd_jd3"><div data-hammer="hammer3"></div></div>
        <div class="hammer hammer1"></div>
        <div class="hammer hammer2"></div>
        <div class="hammer hammer3"></div>
        <div class="zjd_gz">
            <h2>游戏规则：</h2>
            <p>1.100试豆/次</p>
            <p>2.金蛋三选一，蛋蛋有奖，赶紧来一发</p>
        </div>
    </article>
</section>

<?php $this->beginBlock('js');?>
<script src="<?=Yii::getAlias('@static')?>/wap/common/js/jquery-2.2.0.min.js"></script>
<script src="<?=Yii::getAlias('@static')?>/wap/common/js/fastclick.min.js"></script>
<script src="<?=Yii::getAlias('@static')?>/wap/common/js/king.wap.js"></script>
<script>
    $(function(){
        var str1 = '';
        $(".zjd_jd>div").click(function(){
            var _this = this;
            var c = "."+$(this).attr("data-hammer");
            if($(c).hasClass("hammer_hit")||$(c).siblings(".hammer_hit").size()>0){
                return false;
            }else{

                $.doAjax({
                    url: '<?=Yii::$app->urlManager->createUrl(Yii::$app->controller->id . '/to-lottery')?>',
                    type: 'post',
                    success: function(data){

                        if(data.flag && data.prize == 0){
                            str1 = '运气太背，吹口气再来一次！<br>什么也没砸中';
                        }else{
                            str1 = data.msg;
                        }
                        $(c).addClass("hammer_hit");
                        setTimeout(function(){
                            $(_this).parent().addClass("hitted");
                            $(c).removeClass("hammer_hit");
                            setTimeout('alertBox("'+str1+'")',300);
                        },500);
                    }
                });

            }
        });
    });
    function alertBox(p){
        if($.isEmpty(p)){
            $.alert("缺少参数");
            return false;
        }else{
            var html = '<div class="jd_alert_bg" style="display:none;"><div class="jd_alert">'+
                '<div class="jd_close" onclick="gameReset()"></div>'+
                '<p class="jd_text">'+p+'</p>'+
                '<div class="jd_btn" onclick="gameReset()">重新开始</div>'+
                '</div></div>';
            $("body").append(html);
            $(".jd_alert_bg").fadeIn(200);
            $(".jd_alert").css({"transform":"scale(1,1)","-webkit-transform":"scale(1,1)"});
        }
    }
    function gameReset(){
        $(".jd_alert_bg").remove();
        $(".zjd_jd").removeClass("hitted");
    }
</script>
<?php $this->endBlock();?>
